import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JFileChooser;
import java.io.File;
import java.awt.*;
import javax.swing.*;
import java.util.ArrayList;

public class Add_Courses_Frame extends JFrame {
 public JFrame frame = new JFrame();
 public int [] courses;
 public ArrayList <String> courseList;
 public int numofcourses;
 public JTextField Course;
 public User users;
 public int [] thecourses;
 
    int [] get_courses(){
    return thecourses;
    }
	
  int get_numofcourses(){
  return numofcourses;
  }

    Add_Courses_Frame(){

        Course = new JTextField(15);
        JLabel Course_label = new JLabel("Course");


        JPanel panel = new JPanel();
        //Section.setPreferredSize(new Dimension(250,25));
        JButton add_new = new JButton("Add Course");
        JButton close = new JButton("Finished");
        add_new.addActionListener(new ButtonListener1());
        close.addActionListener(new ButtonListener1());
        panel.setLayout(new GridLayout(5,2));
        panel.add(Course_label);
        panel.add(Course);
        panel.add(add_new);
        panel.add(close);
        frame.add(panel);
        frame.setSize(500, 200);
        frame.setVisible(true);




}


class ButtonListener1 implements ActionListener{
    public int i=0;
	public int [] courses;
	public int course;
	public int coursesToStore;
  ButtonListener1() {
      courses = new int[10];
      //int course = 0;
      int i =0;
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("Finished")) {
     frame.setVisible(false);
    }
      else if(e.getActionCommand().equals("Add Course"))
      {

        courses[i] = Integer.parseInt(Course.getText());
        System.out.println(courses[i]);
       // System.out.println(Integer.parseInt(Course.getText()) +" "+i);
        numofcourses = i + 1;
        thecourses = setCourses(courses, numofcourses);
		i++;
      }
  }
  
  int [] setCourses(int [] coursesEntered, int numofcourse)
  {
      int [] coursesToStore = new int[numofcourse];
      for(int i =0;i<numofcourse;i++){
	  
          coursesToStore[i] = coursesEntered[i];
          System.out.println("Added" + coursesToStore[i]);
		  
      }
	  
		//courses = new int [coursesToStore.length];
	 	Course.setText("");
      return coursesToStore;
  }
}
}
